package com.zjw.zy.service.net.factory;


import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.zjw.zy.bean.HourlyWeather;
import com.zjw.zy.bean.UIMode;
import com.zjw.zy.bean.User;
import com.zjw.zy.bean.Weather15Day;
import com.zjw.zy.bean.Weather1Day;
import com.zjw.zy.service.net.conver.HourlyWeatherConverter;
import com.zjw.zy.service.net.conver.DayWeatherConverter;
import com.zjw.zy.service.net.conver.IntegerConverter;
import com.zjw.zy.service.net.conver.UIModeConverter;
import com.zjw.zy.service.net.conver.UserConverter;

import java.lang.annotation.Annotation;
import java.lang.reflect.Type;

import okhttp3.ResponseBody;
import retrofit2.Converter;
import retrofit2.Retrofit;

/**
 * @author ：zhong.jw
 * @date ：Created in 2022/9/27 16:10
 */
public class ConvertFactory extends Converter.Factory {

    private final DayWeatherConverter dayWeatherConverter = new DayWeatherConverter();
    private final HourlyWeatherConverter hourlyWeatherConverter = new HourlyWeatherConverter();
    private final UIModeConverter uiModeConverter = new UIModeConverter();
    private final IntegerConverter integerConverter = new IntegerConverter();
    private final UserConverter userConverter = new UserConverter();

    @Nullable
    @Override
    public Converter<ResponseBody, ?> responseBodyConverter(@NonNull Type type, @NonNull Annotation[] annotations, @NonNull Retrofit retrofit) {
        if (Weather15Day.class.equals(type)) {
            return dayWeatherConverter;
        }
        if (Weather1Day.class.equals(type)) {
            return hourlyWeatherConverter;
        }
        if (UIMode.class.equals(type)) {
            return uiModeConverter;
        }
        if (Integer.class.equals(type)) {
            return integerConverter;
        }
        if (User.class.equals(type)) {
            return userConverter;
        }
        return super.responseBodyConverter(type, annotations, retrofit);
    }
}
